package top.purity.server.tenant.controller;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.purity.framework.common.exception.ServiceException;
import top.purity.framework.common.result.RespResult;
import top.purity.framework.orm.PageResp;
import top.purity.server.tenant.controller.vo.AddTenantUserReqVO;
import top.purity.server.tenant.controller.vo.TenantInfoVO;
import top.purity.server.tenant.controller.vo.TenantTableReqVO;
import top.purity.server.tenant.controller.vo.UpdateTenantUserReqVO;
import top.purity.server.tenant.service.TenantUserService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
public class TenantUserController {

    private final TenantUserService tenantUserService;

    @PostMapping("/add")
    public RespResult add(@RequestBody AddTenantUserReqVO vo) {
        tenantUserService.add(vo);
        return RespResult.ok();
    }

    @PutMapping("/update")
    public RespResult update(@RequestBody UpdateTenantUserReqVO vo) throws ServiceException {
        tenantUserService.update(vo);
        return RespResult.ok();
    }


    @GetMapping("/getInfo")
    @Parameters({
            @Parameter(name = "租户id",description = "租户id", in = ParameterIn.QUERY)
    })
    public RespResult getInfo(@RequestParam("id") Long id) {
        TenantInfoVO tenantInfoVO = tenantUserService.getInfo(id);
        return RespResult.ok(tenantInfoVO);
    }

    @GetMapping("/table")
    @Parameters({
            @Parameter(name = "租户id",description = "租户id", in = ParameterIn.QUERY)
    })
    public RespResult table(TenantTableReqVO reqVO) {
        PageResp<TenantInfoVO> pageResp = tenantUserService.table(reqVO);
        return RespResult.ok(pageResp);
    }

}
